#include <ctime>
#include <iostream>
#include <fstream>

using namespace std;

void bubbleSort(int list[], int listLength) {
    while(listLength--) {
            bool swapped = false;

            for(int i = 0; i < listLength; i++) {
                if(list[i], list[i + 1]) {
                    swap(list[i], list[i + 1]);
                    swapped = true;

                }
            }

            if(swapped == false) break;
    }
}


void read_from_file(const char *filename, int a[], int length)  {
    ifstream file(filename);

    for(int i=0; i < length; i++)
        file >> a[i];
}

int main()
{
int LEN = 5000;
int a1[LEN];
int a2[LEN];
int a3[LEN];

read_from_file("m1_sorted.txt", a1, LEN);
read_from_file("m2_reverse.txt", a2, LEN);
read_from_file("m3_shuffle.txt", a3, LEN);

unsigned int t_s = clock();
bubbleSort(a1, LEN);
unsigned int t_f = clock();
unsigned int t_w = t_f - t_s;
cout<<"m1_sorted " << t_w << " milliseconds \n";

t_s = clock();
bubbleSort(a2, LEN);
t_f = clock();
t_w = t_f - t_s;
cout<<"m2_reverse " << t_w << " milliseconds \n";

t_s = clock();
bubbleSort(a3, LEN);
t_f = clock();
t_w = t_f - t_s;
cout<<"m3_shuffle " << t_w << " milliseconds \n";

return 0;
}
